package com.shunbo.convenient.filter;

import com.shunbo.convenient.service.UserInfoService;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>ClassName: TokenInterceptor</p>
 * <p>Description: 令牌拦截器</p>
 * <p>Company: 科技事业部-大数据风控</p>
 *
 * @author 魏壮
 * @date 18:57 2017/5/26
 */
@Component
public class LogInterceptor implements HandlerInterceptor {

    @Resource
    private UserInfoService userService;


    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o)   {


    /*    if (httpServletRequest.getParameter("token") != null && !httpServletRequest.getParameter("token").equals("")) {
            UserInfo user = new UserInfo();
            user.setToken(httpServletRequest.getParameter("token"));
            UserInfo byToken = userService.findByToken(user);
            if (byToken != null) {
                return true;
            } else {
                httpServletResponse.getWriter().write(JsonUtils.objectToJson(Result.build(503, "token失效或者不存在", false)));
                return false;
            }
        }
        httpServletResponse.getWriter().write(JsonUtils.objectToJson(Result.build(503, "没有访问权限", false)));
        return false;*/
        return true;


    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }


}
